<template>
  <a-card :bordered="false">
    <div class='page_table'>
      <vxe-grid
        ref='xGrid'
        :border='true'
        :resizable='true'
        :showOverflow='true'
        size='mini'
        :loading='loading'
        :height='pageHeight-seachHeight-50'
        :align='left'
        :columns='columns'
        :data='dataSource'
        :toolbar-config="tableToolbar"
       :checkbox-config="checkboxConfig"
        v-bind='vexConfig'
        @checkbox-change='selectChangeEvent'
        @checkbox-all="selectChangeEvent"
      >
        <template #toolbar_buttons>
          <div class='table-operator'>
            <a-button @click='handleAdd' type='primary'>新增</a-button>
            <a-button type='primary' @click="batchDel">删除</a-button>
            <a-button @click='' type='primary'>导出</a-button>
          </div>
        </template>
        <template #action='{ row }'>
          <a @click="handleEdit(row)">编辑</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleConfig(row)">系统配置</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(row.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item>
                <a v-has="'business:log'" href='javascript:;' @click='handleBusiness("登录配置",row)'>日志</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </template>
        <template #pager>
          <vxe-pager
            :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
            :currentPage.sync='ipagination.current'
            :page-size.sync='ipagination.pageSize'
            :total='ipagination.total'
            :pageSizes='ipagination.pageSizeOptions'
            @page-change='handlePageChange'>
          </vxe-pager>
        </template>
      </vxe-grid>
    </div>

    <business-log ref='businessLog'></business-log>
    <tenant-modal ref="modalForm" @ok="modalFormOk"></tenant-modal>
    <tenant-role-modal ref="modalUserRole"></tenant-role-modal>
    <tenant-config ref="modalConfig"></tenant-config>
  </a-card>
</template>

<script>
  import { getAction, httpAction, postAction } from '@/api/manage'
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { PageListMixin } from '@/mixins/PageListMixin'
  import TenantModal from '@page-modules/TenantModal'
  import TenantConfig from '@page-modules/TenantConfig'
  import TenantRoleModal from '@page-modules/TenantRoleModal'
  import {openTenantAccount} from "@api/api";


  export default {
    name: "TenantList",
    mixins:[PageListMixin, mixinDevice],
    components: {
      TenantModal,TenantRoleModal,TenantConfig
    },
    data () {
      return {
        description: '登陆配置',
        // 表头
        columns: [
          { type: 'checkbox', width: 60, fixed: 'left' },

          {
            title:'系统名称',
            minWidth: 80,
            field: 'name'
          },{
            title:'登陆域名',
            minWidth: 80,
            field: 'url'
          },
          {
            title:'开始时间',
            minWidth: 80,
            field: 'beginDate'
          },
          {
            title:'结束时间',
            minWidth: 80,
            field: 'endDate'
          },
          {
            title: '创建人',
            field: 'createName',
            minWidth: 80,
          },
          {
            title: '创建时间',
            field: 'createTime',
            minWidth: 80,
          },
          {
            title: '更新人',
            field: 'updateName',
            minWidth: 80,
          },
          {
            title: '更新时间',
            field: 'updateTime',
            minWidth: 80,
          },
          {
            title: '操作',
            field: 'action',
            align:"center",
            fixed:"right",
            width:120,
            slots: { default: 'action' }
          }
        ],
        url: {
          list:  "/sys/manage/getPageList",
          delete:  "/sys/manage/delete",
          deleteBatch:  "/sys/manage/deleteBatch",
          congfig: '/sys/manage/getConfig'
        },
        dictOptions:{},
      }
    },
    created() {
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      handlePerssion(userId){
        this.$refs.modalUserRole.show(userId);
      },
      handleConfig: async function (record) {
        if (this.url.congfig) {
          const res = await getAction(this.url.congfig, {id: record.id})
          if (res && res.result) {
            record = res.result
          }
        }
        this.$refs.modalConfig.edit(record);
        this.$refs.modalConfig.title = "登陆配置";
        this.$refs.modalConfig.disableSubmit = false;
      },

      handleOpen(saasid){
        const that = this
        this.loading = true
        openTenantAccount({saasid}).then(res=>{
          if(res.success){
            that.$message.success(res.message);
            that.modalFormOk();
          }else{
            that.$message.warning(res.message);
          }
        }).finally(()=> this.loading = false)
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
